import Vue from 'vue'
import App from './App'
import Vant, {Lazyload} from 'vant';
import router from './router'
import store from './store'
import './vue'
import LazyImg from './assets/img/lazy.png'

import '../static/swiper.css'
import filter from './filter.js'
import swiper from '../static/swiper.js'

import ajax from './util/api/zhangkj.js'//我的接口都放在这里面

import 'vant/lib/index.css';
import '@/assets/css/zhangkj.scss'//我的样式都在这里面

import payment from './components/payment.vue'

Vue.component('payment', payment)
Vue.use(Vant);

import Mui from 'vue-awesome-mui';
Vue.use(Mui);

Vue.use(Lazyload, {
  loading: LazyImg
});

Vue.config.productionTip = false
Vue.prototype.$ajax = ajax
Vue.prototype.swiper = swiper
Vue.prototype.$fn = filter

var onPlusReady = function (callback, context = this) {
  if (window.plus) {
    callback.call(context)
  } else {
    document.addEventListener('plusready', callback.bind(context))
  }
}

Vue.mixin({
  beforeCreate() {
    onPlusReady(() => {
      this.plusReady = true
    }, this)
  },
  methods: {
    onPlusReady: onPlusReady
  }
})

/* eslint-disable no-new */
window.vm = new Vue({
  el: '#app',
  router,
  store,
  components: {App},
  template: '<App/>'
})


try{
  mui.init({
    swipeBack: false, //关闭右滑关闭功能（默认就是false）
    keyEventBind: {
      backbutton: true //开启back按键监听（默认就是true）
    }
  });

  var quitTime = null;
  mui.plusReady(function(){
    mui.back = function(){
      if (!quitTime) {
        //记录第一次按下回退键的时间
        quitTime = new Date().getTime();
        //首次按键，提示‘再按一次退出应用’
        mui.toast("再按一次退出应用");
        //回退到上一页面
        window.history.go(-1);
        setTimeout(function() {
          //1s中后清除
          quitTime = null;
        }, 1000);
      }else{
        if((new Date().getTime() - quitTime) < 1000){
          quitTime = null;
          plus.runtime.quit();
        }
      }
    };
  });
}catch(e){
  console.log(e)
}
